package com.lcz.dao;

import com.lcz.bean.User;
import com.lcz.util.DruidUtil;

import javax.swing.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class UserDao {


    //通过传过来的用户密码，得到结果，判定是否登陆成功
    //

    public User login(String username, String password){

        String sql = "select * from user where username = ? and password = ?";
        try {
            ResultSet query = DruidUtil.query(sql, List.of(username, password));
            if(query.next()){
                int id = query.getInt("id");
                return new User(id,username,password);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DruidUtil.close();
        }
        return null;
    }

    }


